Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layers declare their types and number of bottom/top blobs #479

Merged
merged 2 commits into from
Jun 9, 2014

Conversation

jeffdonahue
Copy link
Contributor

This PR attempts to unify/standardize all the "___ Layer takes N blobs as input." messages at the top of each layer's SetUp method throughout the code. Adds 6 methods: ExactNumBottomBlobs, MinBottomBlobs, MaxBottomBlobs, and the analogs for Top, which should be overridden by layers requiring a specific min/max/exact number of bottom/top blobs (which currently is all of them, as far as I know).

The design I settled on was to actually perform these checks in an additional method, CheckBlobCounts, which Net::Init now calls right before SetUp. The drawback is that now any SetUp call is not protected by a blob count check. I also considered just changing the SetUp method to be implemented only in the Layer superclass and just have that method call CheckBlobCounts and FurtherSetUp, which would be the method that subclasses now override (as in the current NeuronLayer and LossLayers) -- do people think this would be a better design? (Or some other design entirely? Definitely open to suggestions.)

@shelhamer
Copy link
Member

Nice unification.

I also considered just changing the SetUp method to be implemented only in the Layer superclass and just have that method call CheckBlobCounts and FurtherSetUp

Since the blob check should be done for every SetUp, I like this design. There's no need for the additional call from Net::Init or elsewhere should SetUp be called -- as fancy layers might that have their own internal layers. Changing the name to FurtherSetup is a little awkward though. Perhaps Layer::SetUp could not be virtual but each layer's SetUp could call the base class's? This isn't totally automatic, but is still concise. This would also allow for a layer that has more complicated blob checking rules that somehow don't fit into exact/min/max (not that I expect that to come up...).

Thoughts?

@jeffdonahue
Copy link
Contributor Author

Yeah, I'd also thought about having each layer make the call to the parent explicitly, but went this way because (as you said) it's more automatic. But I think you're right, it's safer not to have to remember to make an additional call everywhere SetUp is called, so I'll do it that way. Thanks.

@jeffdonahue
Copy link
Contributor Author

Re-implemented as suggested (with base Layer::SetUp calling CheckBlobCounts and each Layer subclass explicitly calling Layer::SetUp). Please take another look when you get a chance, @shelhamer.

@jeffdonahue jeffdonahue mentioned this pull request Jun 9, 2014
@shelhamer
Copy link
Member

Once again, nice tidying up. Thanks Jeff!

shelhamer added a commit that referenced this pull request Jun 9, 2014
…lobs

Layers declare their types and number of bottom/top blobs
@shelhamer shelhamer merged commit cc06ab7 into BVLC:dev Jun 9, 2014
virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_ARGMAX;
}
virtual inline int MinBottomBlobs() const { return 1; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffdonahue I think argmax need to have one bottom blob and can have at at least 1 top blob and at most 2

@jeffdonahue jeffdonahue deleted the declare-layer-names-and-numblobs branch June 9, 2014 05:50
@jeffdonahue
Copy link
Contributor Author

Thanks for noticing that @sguada. I pushed the fix for the bottom blob count directly to dev (see below), but it seems to only support 1 top blob currently (and was previously checking as such) so I left that as is.

[/home/jdonahue/dev/caffe 1]$ g show
commit e17b3fea57b6166a4cd65e604bf5e5e702c08c21
Author: Jeff Donahue <jeff.donahue@gmail.com>
Date:   Sun Jun 8 22:44:32 2014 -0700

    fix ArgMaxLayer bug in num bottom blobs decl. pointed out by @sguada

diff --git a/include/caffe/vision_layers.hpp b/include/caffe/vision_layers.hpp
index eb067bb..fc3dbbe 100644
--- a/include/caffe/vision_layers.hpp
+++ b/include/caffe/vision_layers.hpp
@@ -37,7 +37,7 @@ class ArgMaxLayer : public Layer<Dtype> {
   virtual inline LayerParameter_LayerType type() const {
     return LayerParameter_LayerType_ARGMAX;
   }
-  virtual inline int MinBottomBlobs() const { return 1; }
+  virtual inline int ExactNumBottomBlobs() const { return 1; }
   virtual inline int ExactNumTopBlobs() const { return 1; }

  protected:

mitmul pushed a commit to mitmul/caffe that referenced this pull request Sep 30, 2014
…numblobs

Layers declare their types and number of bottom/top blobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants